/**
 * 此游戏所有的图片资源管理和加载类
 * @author zhouzhanglin
 */
ResManager = function()
{
	EventDispatcher.call( this );

	this._total = 0 ; 
	this._loaded = 0 ;
	this._resArray ;
};
FLASH.extend(ResManager,EventDispatcher);

/**
 * 获取实例
 * @returns
 */
ResManager.getInstance = function()
{
	if(!ResManager._instance){
		ResManager._instance=new ResManager();
	}
	return ResManager._instance ;
};

/**
 * 通过名称来获取图片数据BitmapData
 * @return bitmapData
 */
ResManager.prototype.getBmdByName = function( name){
	return ResPool.getInstance().getResVOByName(name).content.getBitmapData() ;
};

/**
 * 开始下载
 */
ResManager.prototype.startLoad = function()
{
	var resPool = ResPool.getInstance() ;
	this._resArray =[
		new ResVO("apple1", "imgs/apple_01.png"),
		new ResVO("apple2", "imgs/apple_02.png"),
		new ResVO("apple3", "imgs/apple_03.png"),
		new ResVO("apple4", "imgs/apple_04.png"),
		new ResVO("gameButton", "imgs/gameButton.png"),
		new ResVO("xiong", "imgs/xiong.png")
	];
	
	var _self =this ;
	function resQueueLoadedHandler(e){
		resPool.removeEventListener(ResLoadedEvent.RES_QUEUE_LOADED , resQueueLoadedHandler);
		resPool.removeEventListener(ResProgressEvent.RES_LOAD_PROGRESS , resLoadingHandler);
		_self.dispatchEvent( new Event( Event.COMPLETE));
		_self._resArray = null ;
	}
	function resLoadingHandler(e){
		var evt = new ProgressEvent(ProgressEvent.PROGRESS , ( e.getProgress()*100)>>0 , 100 );
		_self.dispatchEvent( evt );
	}
	resPool.addEventListener(ResLoadedEvent.RES_QUEUE_LOADED , resQueueLoadedHandler);
	resPool.addEventListener(ResProgressEvent.RES_LOAD_PROGRESS , resLoadingHandler);
	resPool.queueLoad(this._resArray,4);
};